package cn.ondraw.ragflow.service.impl;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import cn.ondraw.ragflow.pojo.request.GetDialogRequest;
import cn.ondraw.ragflow.pojo.request.ListDialogsRequest;
import cn.ondraw.ragflow.pojo.request.RmDialogRequest;
import cn.ondraw.ragflow.pojo.request.SetDialogRequest;
import cn.ondraw.ragflow.service.RagFlowDialogService;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

/**
 * 对话框服务实现类
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class RagFlowDialogServiceImpl implements RagFlowDialogService {

    private final PythonApiCaller pythonApiCaller;

    private final String URL_PREFIX = "/dialog";

    /**
     * 设置对话框信息
     *
     * @param request 设置对话框请求对象
     * @return 响应实体
     */
    @Override
    public ResponseEntity<?> setDialog(SetDialogRequest request) {
        return pythonApiCaller.callPostApi(URL_PREFIX + "/set", request);
    }

    /**
     * 获取对话框信息
     *
     * @param request 获取对话框请求对象
     * @return 响应实体
     */
    @Override
    public ResponseEntity<?> getDialog(GetDialogRequest request) {
        return pythonApiCaller.callGetApi(URL_PREFIX + "/get?dialog_id=" + request.getDialog_id());
    }

    /**
     * 列出所有对话框信息
     *
     * @param request 列出对话框请求对象
     * @return 响应实体
     */
    @Override
    public ResponseEntity<?> listDialogs(ListDialogsRequest request) {
        return pythonApiCaller.callGetApi(URL_PREFIX + "/list");
    }

    /**
     * 删除对话框信息
     *
     * @param request 删除对话框请求对象
     * @return 响应实体
     */
    @Override
    public ResponseEntity<?> rmDialogs(RmDialogRequest request) {
        return pythonApiCaller.callPostApi(URL_PREFIX + "/rm", request);
    }
}
